package cn.zyx.sys.service;

import cn.zyx.common.properites.CacheProperties;
import cn.zyx.common.utils.cache.redis.RedisUtils;
import cn.zyx.common.utils.sys.SpringContextHolderUtils;
import cn.zyx.sys.entity.AccessKey;
import cn.zyx.sys.entity.User;
import cn.zyx.sys.mapper.AccessKeyMapper;
import cn.zyx.sys.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional(readOnly = true)
public class AccessKeyService {

    @Autowired
    private AccessKeyMapper mapper;

    public AccessKey getInfoByAccessKeyId(String accessKeyId) {
        AccessKey accessKey = RedisUtils.getCacheObject(CacheProperties.ACCESS_KEY_CACHE + accessKeyId);
        if (accessKey == null){
            accessKey = mapper.getInfoByAccessKeyId(accessKeyId);
            if (accessKey == null){
                return null;
            }
            RedisUtils.setCacheObject(CacheProperties.ACCESS_KEY_CACHE + accessKey.getAccessKeyId(), accessKey);
        }
        return accessKey;
    }
}
